define(['app'], function(app) {
	'use strict';

	//实例化方法
	var factory = function(Http) {
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_getbannerlist(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": {"associate": [' +
					'{"associate_id": 1,"associate_type": "type_A","image_id": "./img/upload/siwper-img00.png","d_order": 1},' +
					'{"associate_id": 2,"associate_type": "type_A","image_id": "./img/upload/siwper-img01.png","d_order": 2},' +
					'{"associate_id": 2,"associate_type": "type_A","image_id": "./img/upload/siwper-img02.png","d_order": 3}' +
					']},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_detail(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "",' +
					'"result": {"act_id": "001","name": "促销","start_time": "2017/01/01 09:00:00","end_time": "2017/01/31 09:00:00","create_group": true,"has_packets": true,"image": [{"id": "001","image": ""},{"id": "002","image": ""}],"brand_id": "001","cat_type": [{"id": "001"},{"id": "002"}]},' +
					'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}
		/**
		 * 一键切换数据获取方式
		 * @param {Object} result
		 */
		function get_data_winninglist(result) {
			if(false) {
				result = '{"success": true,"msg": "","result": ' +
					'{"winner": [{"name": "张三","order_id": "001"},{"name": "李四","order_id": "002"}]},' +
					'"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else {
				return result;
			}
		}

		function get_data_seckill_goods(result) {
			if(HTTP_ISLOGIC) {
				result = '{"success": true,"msg": "","result": {"store_count": "500","data": [' +
					'{"goods_id": 1,"name": "十字螺丝刀","introduce": "十字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1",' +
					'"store_name": "五金一店","image": "./img/upload/pro-img02.jpg","storenumber": 100,"salenumber": 20,"personlimit": 3,"qq": "1234567","phone": "18912345678"},' +
					'{"goods_id": 2,"name": "一字螺丝刀","introduce": "一字螺丝刀","price": 5.5,"mktprice": 8,"preprice": 5.5,"store_id": "WuJin_1",' +
					'"store_name": "五金一店","image": "./img/upload/pro-img02.jpg","storenumber": 80,"salenumber": 10,"personlimit": 3,"qq": "1234567","phone": "18912345678"}]},"session": "7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}

		function get_data_detail_list(result) {
			if(false) {
				result = '{"success":true,"msg":"","result":{"act_id":"001","name":"团购","introduction":"活动简介","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","group_id":"123456789","image":[{"id":"001","image":"./img/upload/siwper-img00.png"},{"id":"001","image":"./img/upload/siwper-img00.png"},{"id":"001","image":"./img/upload/siwper-img00.png"}],"follow_count":520,"deal_count":20,"goods":[{"id":"001","name":"电动手枪钻","price":"1000.00","seckill_price":"800.00","store":541,"limit_buy_num":10,"image":[{"id":"001","image":"./img/upload/pro-img02.jpg"}]},{"id":"002","name":"电动冲击钻","price":"1000.00","seckill_price":"800.00","store":541,"limit_buy_num":10,"image":[{"id":"002","image":"./img/upload/pro-img02.jpg"}]}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
				return JSON.parse(result);
			} else
				return result;
		}
		//返回信息
		return {
			//获取轮播图
			getbannerlist: function(callback) {
				Http.post({
						method: 'homepage.banner.getbannerlist',
						picSize: 'CS',
						pagelimit: 8,
						nPage: 1
					},
					function(result) {
						//请求成功
						if(callback)
							callback(get_data_getbannerlist(result).result);
					},
					function(e) {
						//请求异常
					},
					function() {
						//请求完成，一般不做什么事情
					}
				);
			},
			//获取详细数据
			get_detail: function(act_id, callback, calldone) {
				Http.post({
					"method": "marketing.seckill.detail",
					"act_id": act_id
				}, function(result) {
					if(callback)
						callback(get_data_detail(result).result);
				}, function(err) {

				}, function() {
					if(calldone)
						calldone();
				});
			},
			//中奖名单
			get_winninglist: function(act_id, callback, calldone) {
				Http.post({
					method: "marketing.seckill.winninglist",
					act_id: act_id
				}, function(result) {
					if(callback)
						callback(get_data_winninglist(result).result);
				}, function(err) {

				}, function() {
					if(calldone)
						calldone();
				});
			},
			seckill_goods: function(key, orderby, region, store_cat, act_id, callback) {
				Http.post({
					method: 'goods.search.getlist',
					cat_type: 4,
					
					pagelimit: 8,
					nPage: 1,
					show_count: 5,
					orderby: orderby,
					picSize: 'CS',
					region: region,
					store_cat: store_cat,
					act_id: act_id
				}, function(result) {
					if(callback)
						callback(get_data_seckill_goods(result).result);
				}, function(e) {

				}, function() {

				})
			},
			detail_list: function(act_id, callback) {
				Http.post({
					method: 'marketing.seckill.view',
					act_id: act_id,
					picSize: 'CS'
				}, function(result) {
					if(callback)
						callback(get_data_detail_list(result),result.process_time);
				}, function(e) {

				}, function() {

				})
			},
			get_loginfo:function(callback){
				Http.post({
					method:'chat.group.getlogininfo'
				},function(result){
					if(callback)
					callback(result.result);
				})
			},
			join_group:function(group_id,callback){
				Http.post({
					method:'chat.group.joingroup',
					group_id:group_id,
					is_activity:true
				},function(result){
					if(callback)
					callback(result.result);
				})
			}
		};
	}

	factory.$inject = ['Http'];
	return app.registerService("Seckilldetail", factory);
});